﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt">
  <xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes" />
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
          body {
          margin-top: 10px;
          margin-left: 10px;
          margin-right: 10px;
          margin-bottom: 10px;
          }
          table {
          font-family: Tahoma;
          font-size: 11px;
          }
          .datatable {
          font-family: Tahoma;
          font-size: 11px;
          border-top: 1px RGB(212,208,200) solid;
          border-left: 1px RGB(212,208,200) solid;
          border-right: 1px RGB(212,208,200) solid;
          border-bottom: 1px RGB(212,208,200) solid;
          padding: 0px;
          }
          td {
          text-align: center;
          padding-left:10px;
          padding-right:10px;
          }
          th {
          background:#CCCCCC;
          border-right: #666666 1px solid;
          border-bottom: #666666 1px solid;
          padding-left:10px;
          padding-right:10px;
          }
          .attribute {
          background:#CCCCCC;
          border-right: #666666 1px solid;
          border-bottom: #666666 1px solid;
          padding-left:10px;
          padding-right:10px;
          }
          .section1 {
          padding-top: 10px;
          padding-bottom: 10px;
          padding-left: 10px;
          padding-right: 10px;
          font-weight: bold;
          background: rgb(234,242,255);
          border-bottom: 1px solid rgb(120,172,255);
          }
          .section2 {
          text-align:left;
          border-bottom: green 1px solid;
          padding-bottom: 5px;
          padding-left: 10px;
          padding-right: 10px;
          background: #e9ffcb;
          font-weight: bold;
          padding-top: 5px
          }
          .section3 {
          font-weight: bolder;
          padding-left: 10px;
          padding-top: 10px;
          }

          .headleft {
          text-align: left;
          padding-left: 10px;
          padding-right: 5px;
          padding-top: 2px;
          padding-bottom: 2px;
          font-weight: normal;
          white-space: nowrap;
          background-color: RGB(212,208,200);
          }
          .headcenter {
          text-align: center;
          padding-left: 10px;
          padding-right: 5px;
          padding-top: 2px;
          padding-bottom: 2px;
          font-weight: normal;
          white-space: nowrap;
          background-color: RGB(212,208,200);
          }
          .leftdata {
          padding-left: 10px;
          padding-right: 10px;
          white-space: nowrap;
          font-weight: normal;
          text-align: left;

          }
          .centerdata {
          padding-left: 10px;
          padding-right: 10px;
          white-space: nowrap;
          text-align: center;
          font-weight: normal;
          }
        </style>
        <title>Metaverse Attribute Flow Documenter</title>
      </head>
      <body>
        <table class="datatable" id="curdata" name="curdata">
          <tr>
            <td class="section1" colspan="10">
              <xsl:text>Metaverse Attribute Flow Configuration</xsl:text>
            </td>
          </tr>
          <xsl:for-each select="//flow-set">
            <tr>
              <td class="section2" colspan="10">
                <xsl:text>Metaverse object type: </xsl:text>
                <xsl:value-of select="@mv-object-type" />
              </td>
            </tr>
            <xsl:for-each select="flows">
              <tr>
                <th>Metaverse Attribute</th>
                <th>Flow Type</th>
                <th>MA Name</th>
                <th>Precedence</th>
                <th>CS Object Type</th>
                <th>CS Attributes</th>
                <th>Mapping Type</th>
                <th>Advanced Flow Options</th>
                <th>Additional Metaverse Attributes</th>
                <th>Flow Nulls</th>
              </tr>
              <xsl:variable name="count" select="count(*)" />
              <xsl:variable name="mvattr" select="@mv-attribute" />
              <xsl:variable name="ptype" select="@type" />
              <xsl:for-each select="*">
                <tr>
                  <xsl:if test="(position() mod 2 = 0)">
                    <xsl:attribute name="bgcolor">#EEEEFF</xsl:attribute>
                  </xsl:if>
                  <xsl:if test="(position()= 1)">
                    <td class="attribute" rowspan="{$count}">
                      <xsl:value-of select="$mvattr" />
                    </td>
                  </xsl:if>
                  <td>
                    <xsl:choose>
                      <xsl:when test="ms:string-compare(name(),'import-flow')=0">
                        <xsl:text>Inbound</xsl:text>
                      </xsl:when>
                      <xsl:when test="ms:string-compare(name(),'export-flow')=0">
                        <xsl:text>Outbound</xsl:text>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:text>Unknown</xsl:text>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                  <td>
                    <xsl:variable name="guid" select="@src-ma" />
                    <xsl:value-of select="//ma-data/ma[@guid=$guid]/@name" />
                  </td>
                  <td>
                    <xsl:if test="ms:string-compare(name(),'import-flow')=0">
                      <xsl:choose>
                        <xsl:when test="ms:string-compare($ptype,'ranked')=0">
                          <xsl:value-of select="position()" />
                        </xsl:when>
                        <xsl:when test="ms:string-compare($ptype,'manual')=0">
                          <xsl:text>Manual</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:text>Unknown</xsl:text>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:if>
                  </td>
                  <td>
                    <xsl:value-of select="@cd-object-type" />
                  </td>
                  <td>
                    <xsl:choose>
                      <xsl:when test="ms:string-compare(name(),'import-flow')=0">
                        <xsl:for-each select="*/src-attribute">
                          <xsl:value-of select="." />
                          <xsl:if test="not(position() = last())">
                            <xsl:text>, </xsl:text>
                          </xsl:if>
                        </xsl:for-each>
                      </xsl:when>
                      <xsl:when test="ms:string-compare(name(),'export-flow')=0">
                        <xsl:value-of select="@cd-attribute" />
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:text>Unknown</xsl:text>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                  <td>
                    <xsl:choose>
                      <xsl:when test="scripted-mapping">
                        <xsl:text>Rules extension</xsl:text>
                      </xsl:when>
                      <xsl:when test="direct-mapping">
                        <xsl:text>Direct</xsl:text>
                      </xsl:when>
                      <xsl:when test="constant-mapping">
                        <xsl:text>Constant</xsl:text>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:text>Unknown</xsl:text>
                      </xsl:otherwise>
                    </xsl:choose>
                  </td>
                  <td>
                    <xsl:if test="scripted-mapping">
                      <xsl:value-of select="scripted-mapping/script-context" />
                    </xsl:if>

                    <xsl:if test="constant-mapping">
                      Constant value: <xsl:value-of select="constant-mapping/constant-value" />
                    </xsl:if>
                  </td>
                  <td>
                    <xsl:if test="ms:string-compare(name(),'export-flow')=0">
                      <xsl:for-each select="scripted-mapping/src-attribute[. != $mvattr]">
                        <xsl:value-of select="." />
                        <xsl:if test="not(position() = last())">
                          <xsl:text>, </xsl:text>
                        </xsl:if>
                      </xsl:for-each>
                    </xsl:if>
                  </td>
                  <td>
                    <xsl:if test="ms:string-compare(name(),'export-flow')=0">
                      <xsl:choose>
                        <xsl:when test="ms:string-compare(@suppress-deletions,'false')=0">
                          <xsl:text>yes</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:text>no</xsl:text>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:if>                    
                  </td>
                </tr>
              </xsl:for-each>
            </xsl:for-each>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
